<%--
  Created by IntelliJ IDEA.
  User: sofwin
  Date: 2021/7/13
  Time: 16:34
  To change this template use File | Settings | File Templates.
--%>
<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<%@taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
<%String path = request.getContextPath()+"/";%>
<!doctype html>
<html>
<head>
    <base href="<%=path%>">
    <title>编辑用户信息</title>
    <link href="bootstrap/css/bootstrap.min.css?v=3.3.7" rel="stylesheet">
    <%--    <link href="bootstrap/css/plugins/bootstrap-table/bootstrap-table.min.css" rel="stylesheet">--%>
    <script type="text/javascript" src="bootstrap/js/jquery.min.js"></script>
    <script type="text/javascript" src="bootstrap/js/bootstrap.min.js"></script>
    <script type="text/javascript" src="bootstrap/js/plugins/layer/layer.min.js"></script>
    <link href="bootstrap/css/font-awesome.css?v=4.4.0" rel="stylesheet">
    <link href="bootstrap/css/plugins/iCheck/custom.css" rel="stylesheet">
    <link href="bootstrap/css/animate.css" rel="stylesheet">
    <link href="bootstrap/css/style.css?v=4.1.0" rel="stylesheet">
    <script src="http://static.runoob.com/assets/jquery-validation-1.14.0/dist/jquery.validate.min.js"></script>
    <script src="bootstrap/js/plugins/validate/messages_zh.min.js"></script>

    <script type="text/javascript" src="bootstrap/js/ry.js"></script>
<style>
    input{
        width:60%;
    }
</style>
</head>
<body>
<form class="form-horizontal" id="deptForm">
    <input type="hidden" name="deptId" value="${dept.deptId}"/>
    <div class="form-group">
        <label for="parentId" class="col-sm-2 control-label">上级部门</label>
        <div class="col-sm-4">
            <input type="text" id="showName" class="form-control" readonly placeholder="" value="${dept.parent.deptName}" style="width:200px;" ><a href="javascript:void(0)" id="choose">选择</a>
            <input type="hidden" name="parentId" id="parentId" value="${dept.parentId}"/>

        </div>
    </div>
    <div class="form-group">
        <label for="deptName" class="col-sm-2 control-label">部门名称</label>
        <div class="col-sm-4">
            <input type="text" class="form-control" id="deptName" value="${dept.deptName}" name="deptName" placeholder="Password">
        </div>
    </div>
    <div class="form-group">
        <label for="deptSort" class="col-sm-2 control-label" >显示排序</label>
        <div class="col-sm-4">
            <input type="text" class="form-control" id="deptSort" value="${dept.deptSort}" name="deptSort" placeholder="Password">
        </div>
    </div>
    <div class="form-group">
        <label for="status" class="col-sm-2 control-label">用户状态</label>
        <div class="col-sm-4">
            <select class="form-control" name="status" id="status">
                <option value="1" <c:if test="${dept.status==1}">selected</c:if>>启用</option>
                <option value="0" <c:if test="${dept.status==0}">selected</c:if>>禁用</option>
            </select>
        </div>
    </div>
    <div class="form-group">
        <div class="col-sm-offset-2 col-sm-10">
            <button type="button" id="save" class="btn btn-default">
            <i class="fa fa-save"></i>
                保存</button>
            <button type="reset"  class="btn btn-default">
                <i class="fa fa-refresh"></i>
                重置</button>
        </div>
    </div>
</form>
</body>
<script>
    $(function(){
        $("#choose").click(function(){
           $.modal.open("请选择上级部门",'view/dept/tree',"400px","400px");
        });
        $("#deptForm").validate({
            rules:{
                deptName:{
                  required:true,
                  remote:function () {
                        if($("#parentId")!=null){
                            if($("#deptName").val()=='${dept.deptName}'){
                                return true;
                            }
                        }
                        $.modal.get('dept/checkUnique?deptName='+$("#deptName").val(),function(ret){
                            return ret;
                        });
                  }
                },
                deptSort:{
                    required:true,
                    number:true
                }
            },
            messages:{
                deptName:{
                    required:"部门名称不能为空",
                    remote:'部门名称不能重复'
                }
            }
        });
        $("#save").click(function(){
            let s = $("#deptForm").valid();// 调用验证规则对表单进行验证
            if(s){
                $.modal.saveWindow('dept/save',$("form").serialize());
            }
        })
    })
</script>
</html>
